package com.token.iot.bratterycharging.gateway.business;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.esotericsoftware.minlog.Log;
import com.outstanding.framework.core.PendingException;
import com.token.iot.bratterycharging.gateway.IDGeneration;
import com.token.iot.bratterycharging.gateway.OperExchanger;
import com.token.iot.bratterycharging.gateway.utils.ByteUtil;

/**
 * 查询整机充电状态
 * 
 * @author chenzhixuan
 *
 */

@Component("CQZDuplexProcessor")
public class CQZDuplexProcessor extends DuplexProcessor {

	@Override
	public String request(String imei, Map<String, String> params) throws PendingException {
		String c = "CQZ";
		String sessionId = IDGeneration.createSeesionID();
		String command = null;
		command = c + sessionId + "/0";
		loger.info("the send =" + new String(command));
		byte[] cc = ByteUtil.addFlag(command.getBytes());
		// 进行响应码转换
		OperExchanger.register("CQZ", "CQS");
		context.writeAndFlush(cc);
		return sessionId;

	}

	@Override
	public Boolean response(String response) throws PendingException {
		String val = response.substring(14);
		loger.info("the CQZ response="+response);
		String[] params = val.split("#/#");
		for (String str : params) {
			loger.info(str);
		}
		return true;
	}

}